import * as dictionaryService from '../services/dictionary'

export default {
  namespace: 'dictionary',
  state: { },
  effects: {
    // 初始化字典
    *fetchDic({}, { call }) {
      if (null == localStorage.getItem('_DICTIONARY')){
        const { data } = yield call(dictionaryService.fetch, null);
        localStorage.setItem('_DICTIONARY', JSON.stringify(data))
      }
    },
  },
  subscriptions: {
    setup({dispatch, history}) {
      return history.listen(({}) => {
          dispatch({type: 'fetchDic'})
      });
    },
  },
};
